package com.spzx.channel.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.channel.domain.vo.IndexVO;
import com.spzx.channel.service.IndexService;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.Brand;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.query.ProductSkuQuery;
import com.spzx.product.api.domain.vo.ProductSkuVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping
@Tag(name = "首页模块")
public class IndexlController extends BaseController {
    @Resource
    IndexService indexService;

    @Operation(summary = "首页加载一集分类集合和热门数据")
    @GetMapping("index")
    public AjaxResult index() {

     IndexVO indexVO = indexService.getIndexPageData();
        return success(indexVO);
    }



    ///list/skuList/1/10

    @Operation(summary = "条件查询商品分页列表")
    @GetMapping("list/skuList/{pageNum}/{pageSize}")
    public TableDataInfo skuList(ProductSkuQuery query){
        Page<ProductSku> page = indexService.getSkuList(query);
        return getDataTable(page);
    }





    @Operation(summary = "内部调用接口：查询所有品牌")
    @GetMapping("brand/getBrandAll")
    public AjaxResult getBrandAll(){
    List<Brand>  brands = indexService.getBrandAll();
    return success(brands);
    }


    @Operation(summary = "内部调用接口：查询商品详情")
    @GetMapping("/item/{skuId}")

    public AjaxResult getSkuById(@PathVariable("skuId")Long skuId){
        ProductSkuVO skuVO = indexService.getSkuById(skuId);
        return success( skuVO);
    }



    @Operation(summary = "测试缓存")
    @GetMapping("lock/test/")
    public AjaxResult test(){
      indexService.testCache();
        return success();
    }
}
